<!DOCTYPE html>
<html lang = "en" >
<head >
  <meta charset = "UTF-8" >
  <title >Django模板</title >
</head >
<body >
<h2>Django模板</h2>
<hr >

<h2>empty</h2>
{% for like in likes2 %}
    <p>{{ like }}</p>
    {% empty %}
    <p>likes2为空</p>
{% endfor %}


<h2>下标</h2>
{% for like in likes %}
<p>
    counter0: {{ forloop.counter0 }},
    counter: {{ forloop.counter }},
    revcounter0: {{ forloop.revcounter0 }},
    revcounter: {{ forloop.revcounter }},

    {% if forloop.first %}
        <b>- first</b>
    {% endif %}

    {% if forloop.last %}
    <b>- last</b>
    {% endif %}
    </p>
{% endfor %}

<h2>循环嵌套</h2>
<table border="1", width="300">
    {% for start in starts %}
        <tr>
            {% for s in start %}
                <td>
                    {{ s }}-
                    {{ forloop.parentloop.counter }}-
                    {{ forloop.counter }}
                </td>
            {% endfor %}

        </tr>
    {% endfor %}
</table>

<br ><br ><br >
<br ><br ><br >
<h2>过滤器</h2>
<p>age = {{  age }}</p>
<p>age|add:2 = {{  age|add:2 }}</p>  # +2
<p>age|add:-2 = {{  age|add:-2 }}</p>  # -2

<p>name = {{ name }}</p>
<p>name|first|upper = {{ name|first|upper }}</p>  # 首字母大写
<p>name|last|lower = {{ name|last|lower }}</p>  # 尾字母小写
<p>name|title = {{ name|title }}</p>
<p>name|truncatechars:7 = {{ name|truncatechars:7 }}</p>  # 表示将 name 的值截断到前 7 个字符。
<p>name|truncatechars:17 = {{ name|truncatechars:17 }}</p>  #表示将 name 的值截断到前 17 个字符。

<p>likes: {{ likes }}</p>
<p>likes|join:'+':  {{ likes|join:'+' }}</p>  # 拼接


<br ><br ><br ><br >
<br ><br ><br ><br >
<h2>模板继承</h2>
block:
    {% block %}
</body >
</html >